package com.hxc.configs.db;

import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

@Component
public class PrimeDB {

  private final DataSource primeDataSource;

  @Autowired
  public PrimeDB(@Qualifier("primeDataSource")DataSource primeDataSource) {
    this.primeDataSource = primeDataSource;
  }

  public Connection create() throws SQLException {
    Connection connection = null;
    try {
      connection = primeDataSource.getConnection();
      return connection;
    } catch (SQLException e) {
      // 处理连接获取失败的异常情况
      throw new RuntimeException("连接数据库失败：", e);
    }
  }
}
